﻿using JinJun.YShowReception.BLL.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JinJun.YShowReception.DAL.IRepository;
using JinJun.YShowReception.Model;

namespace JinJun.YShowReception.BLL.Service
{
    public class UserInfoService:IUserInfoService
    {
        private IUserInfoRepository _userInfoRepository;
        public UserInfoService(IUserInfoRepository userInfoRepository)
        {
            _userInfoRepository = userInfoRepository;
        }


        /// <summary>
        /// 用户登录方法
        /// </summary>
        /// <param name="adminInfo"></param>
        /// <returns></returns>
        public UserInfo LoginUserInfo(UserInfo userInfo)
        {
            int option = -1;
            UserInfo user = _userInfoRepository.LoginUserInfo(userInfo);
            //调用用户登录方法
            bool result = user!=null;
            //如果登录成功即同时修改登录时间
            if (result)
            {
                option = _userInfoRepository.UpdateLoginTime(userInfo);
                if (option > 0)
                {
                    return user;
                }
            }
            return null;
        }


        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int AddUserInfo(UserInfo userInfo)
        {          
            //调用用户注册添加方法
            return _userInfoRepository.AddUserInfo(userInfo);
        }


        /// <summary>
        /// 查询手机号
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int CheckUserTel(UserInfo userInfo)
        {     
            //调用查询手机号
            return _userInfoRepository.CheckUserTel(userInfo);
        }


        /// <summary>
        /// 查询用户名
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int CheckUserName(UserInfo userInfo)
        {          
            // 调用查询用户名方法
            return _userInfoRepository.CheckUserName(userInfo);
        }
    }
}
